#coding=utf-8
#Boa:Dialog:DlgPopupSupplier

import wx

import DlgEditorSupplier

from MyListCtrl import MySupplierListCtrl



def create(parent):
    return DlgPopupSupplier(parent)

[wxID_DLGPOPUPSUPPLIER, wxID_DLGPOPUPSUPPLIERBTNADD, 
 wxID_DLGPOPUPSUPPLIERBTNCANCEL, wxID_DLGPOPUPSUPPLIERBTNMODIFY, 
 wxID_DLGPOPUPSUPPLIERBTNREFRESH, 
] = [wx.NewId() for _init_ctrls in range(5)]

class DlgPopupSupplier(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGPOPUPSUPPLIER,
              name=u'DlgPopupSupplier', parent=prnt, pos=wx.Point(166, 307),
              size=wx.Size(808, 574), style=0,
              title=u'\u9009\u62e9\u4f9b\u5e94\u5546')
        self.SetClientSize(wx.Size(800, 540))

        self.btnAdd = wx.Button(id=wxID_DLGPOPUPSUPPLIERBTNADD,
              label=u'\u65b0\u589e\u5ba2\u6237', name=u'btnAdd', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(75, 24), style=0)
        self.btnAdd.Bind(wx.EVT_BUTTON, self.OnBtnAddButton,
              id=wxID_DLGPOPUPSUPPLIERBTNADD)

        self.btnModify = wx.Button(id=wxID_DLGPOPUPSUPPLIERBTNMODIFY,
              label=u'\u4fee\u6539', name=u'btnModify', parent=self,
              pos=wx.Point(80, 0), size=wx.Size(75, 24), style=0)
        self.btnModify.Bind(wx.EVT_BUTTON, self.OnBtnModifyButton,
              id=wxID_DLGPOPUPSUPPLIERBTNMODIFY)

        self.btnCancel = wx.Button(id=wxID_DLGPOPUPSUPPLIERBTNCANCEL,
              label=u'\u9000\u51fa', name=u'btnCancel', parent=self,
              pos=wx.Point(700, 0), size=wx.Size(75, 24), style=0)
        self.btnCancel.Bind(wx.EVT_BUTTON, self.OnBtnCancelButton,
              id=wxID_DLGPOPUPSUPPLIERBTNCANCEL)

        self.btnRefresh = wx.Button(id=wxID_DLGPOPUPSUPPLIERBTNREFRESH,
              label=u'\u5237\u65b0\u5217\u8868', name=u'btnRefresh',
              parent=self, pos=wx.Point(616, 0), size=wx.Size(75, 24), style=0)
        self.btnRefresh.Bind(wx.EVT_BUTTON, self.OnBtnRefreshButton,
              id=wxID_DLGPOPUPSUPPLIERBTNREFRESH)

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.myInit()
        
    def myInit(self):
        self.SetSize(wx.Size(800, 400))
        
        self.listCtrl = MySupplierListCtrl(self)
        self.listCtrl.SetSize(wx.Size(800, 375))
        self.listCtrl.Move(wx.Point(0, 25))
        #self.listCtrl.refresh() # 提高打开效率
        
        self.listCtrl.Bind(wx.EVT_LEFT_DCLICK, self.OnSelectItem)
        
    def setFilter(self, str):
        self.listCtrl.refresh({'all':str})
        
    def OnSelectItem(self, event):
        obj = self.listCtrl.getSelectObj()
        if(obj is not None):
            self.GetParent().setSelectPeer(obj)
            self.Show(False)
    
    def OnBtnAddButton(self, event):
        dlg = DlgEditorSupplier.create(self)
        if (dlg.ShowModal() == wx.ID_OK):
            self.GetParent().setSelectPeer(dlg.curObj)
            self.listCtrl.refresh()
            self.Show(False)
    
    def OnBtnModifyButton(self, event):
        '''修改选中的客户信息'''
        obj = self.listCtrl.getSelectObj()
        if(obj is None):
            dlg = wx.MessageDialog(self, u'请选择列表项目', u'提示',
                                    wx.OK|wx.ICON_ERROR)
            dlg.ShowModal()
            return
        
        dlg = DlgEditorSupplier.create(self)
        dlg.setEditObj(obj)
        if (dlg.ShowModal() == wx.ID_OK):
            self.listCtrl.refresh()
        
    def OnBtnCancelButton(self, event):
        self.Show(False)

    def OnBtnRefreshButton(self, event):
        self.listCtrl.refresh()
        
